package com.imchen.demov4;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

/**
 * @Description
 * @Author imchen
 * @CreateTime 2019/10/8 16:34
 */
public class TestInstance {

    public static TestInstance mInstance;

    public static ImageView imageView;

    private static  int testInt;

    public static Object getInstance(){
        if (mInstance==null){
            mInstance=new TestInstance();
        }
        return mInstance;
    }

    private void onCreate(){
        mInstance=this;
        testInt=3;
    }

    public void show(){
        System.out.println("1234");
        mInstance=this;
        imageView=new ImageView(null);
        imageView.setVisibility(View.GONE);
    }

    public void ifElse(Context context){
        if (isPurchase(context)){
            Log.d("TAG", "if: ");
        }else {
            Log.d("TAG", "else: ");
        }
    }

    public static int getSPInt(Context context,String key){
        SharedPreferences preferences=context.getSharedPreferences("mod",Context.MODE_PRIVATE);
        return preferences.getInt(key,0);
    }

    public static void  setSPInt(Context context,String key,int value){
        SharedPreferences preferences=context.getSharedPreferences("mod",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor=preferences.edit();
        editor.putInt(key,value);
        editor.apply();
    }

    public static boolean isPurchase(Context context){
        int pro= getSPInt(context,"pro");
        return pro == 1;
    }

    public static void setPurchase(Context context){
        setSPInt(context,"pro",1);
    }

    public void ifElse(String a ){
        if ("asdf".equals(a)){
            show();
            System.out.println(testInt);
        }else {
            onCreate();
        }
    }

    public void testArgs(int b,String name){
        int a=b;
        int c=b;
        String aName=name;
        String bName=name;
    }

}
